using UnityEngine;

[ExecuteInEditMode]
public class ColorChangerArray : MonoBehaviour
{
	private Color _color;

	public Color MeshColor;

	public ColorChanger[] ColorChangers;

	private void Start()
	{
		if (!Application.isPlaying && ColorChangers != null)
		{
			ColorChangers = null;
		}
		if (ColorChangers == null || ColorChangers.Length == 0)
		{
			ColorChangers = GetComponentsInChildren<ColorChanger>();
		}
		_color = MeshColor;
		UpdateColor();
	}

	private void UpdateColor()
	{
		for (int i = 0; i < ColorChangers.Length; i++)
		{
			ColorChangers[i].SetColor(_color);
		}
	}

	public void SetColor(Color iColor)
	{
		if (iColor != _color)
		{
			_color = iColor;
			UpdateColor();
		}
	}
}
